[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

libdrm: Changes to 'upstream-unstable'



 configure.ac                        |   15 
 libdrm/Makefile.am                  |    6 
 libdrm/intel/intel_bufmgr_gem.c     |   82 -
 libdrm/nouveau/libdrm_nouveau.pc.in |    2 
 libdrm/nouveau/nouveau_bo.c         |  191 +-
 libdrm/nouveau/nouveau_bo.h         |   22 
 libdrm/nouveau/nouveau_device.c     |    6 
 libdrm/nouveau/nouveau_device.h     |    2 
 libdrm/nouveau/nouveau_drmif.h      |    3 
 libdrm/nouveau/nouveau_private.h    |    1 
 libdrm/nouveau/nouveau_pushbuf.c    |    4 
 libdrm/nouveau/nouveau_pushbuf.h    |   23 
 libdrm/radeon/Makefile.am           |   54 
 libdrm/radeon/libdrm_radeon.pc.in   |   10 
 libdrm/radeon/radeon_bo.h           |  187 ++
 libdrm/radeon/radeon_bo_gem.c       |  270 +++
 libdrm/radeon/radeon_bo_gem.h       |   43 
 libdrm/radeon/radeon_cs.h           |  237 +++
 libdrm/radeon/radeon_cs_gem.c       |  457 ++++++
 libdrm/radeon/radeon_cs_gem.h       |   41 
 libdrm/radeon/radeon_cs_space.c     |  234 +++
 libdrm/radeon/radeon_track.c        |  140 +
 libdrm/radeon/radeon_track.h        |   64 
 libdrm/xf86drm.c                    |   49 
 linux-core/Makefile                 |    2 
 linux-core/Makefile.kernel          |    7 
 linux-core/drmP.h                   |   21 
 linux-core/drm_agpsupport.c         |  171 --
 linux-core/drm_bo.c                 | 2730 ------------------------------------
 linux-core/drm_bo_lock.c            |  189 --
 linux-core/drm_bo_move.c            |  614 --------
 linux-core/drm_compat.c             |   99 -
 linux-core/drm_drv.c                |   36 
 linux-core/drm_fence.c              |  829 ----------
 linux-core/drm_fops.c               |   35 
 linux-core/drm_object.c             |  294 ---
 linux-core/drm_objects.h            |  821 ----------
 linux-core/drm_os_linux.h           |    8 
 linux-core/drm_proc.c               |  102 -
 linux-core/drm_stub.c               |   14 
 linux-core/drm_sysfs.c              |    8 
 linux-core/drm_ttm.c                |  512 ------
 linux-core/drm_vm.c                 |  198 --
 linux-core/nouveau_backlight.c      |   93 +
 linux-core/via_buffer.c             |  163 --
 linux-core/via_fence.c              |  169 --
 linux-core/xgi_cmdlist.c            |    3 
 linux-core/xgi_drv.c                |   11 
 linux-core/xgi_drv.h                |   12 
 linux-core/xgi_fence.c              |   87 -
 shared-core/drm.h                   |  319 ----
 shared-core/i915_drm.h              |   52 
 shared-core/nouveau_drm.h           |   35 
 shared-core/nouveau_drv.h           |    2 
 shared-core/nouveau_reg.h           |    4 
 shared-core/nv50_graph.c            |    1 
 shared-core/radeon_drm.h            |  131 +
 shared-core/via_drv.c               |   40 
 shared-core/via_drv.h               |   14 
 shared-core/via_map.c               |   10 
 tests/modetest/modetest.c           |    2 
 61 files changed, 2292 insertions(+), 7689 deletions(-)

New commits:
commit eea95ed8af24300e5a5d2489dfe0d73c24300651
Author: Eric Anholt <eric@anholt.net>
Date:   Wed Jul 15 10:04:44 2009 -0700

    Bump to version 2.4.12 for release.

diff --git a/configure.ac b/configure.ac
index 1db781c..0794a2c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,7 +19,7 @@
 #  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 AC_PREREQ(2.60)
-AC_INIT([libdrm], 2.4.11, [dri-devel@lists.sourceforge.net], libdrm)
+AC_INIT([libdrm], 2.4.12, [dri-devel@lists.sourceforge.net], libdrm)
 AC_USE_SYSTEM_EXTENSIONS
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([dist-bzip2])

commit 3f3c5be6f908272199ccf53f108b1124bfe0a00e
Author: Eric Anholt <eric@anholt.net>
Date:   Thu Jul 9 17:49:46 2009 -0700

    intel: Free buffers in the BO cache that haven't been reused in a while.
    
    The goal of the BO cache is to keep buffers on hand for fast continuous use,
    as in every frame of a game or every batchbuffer of the X Server.  Keeping
    older buffers on hand not only doesn't serve this purpose, it may hurt
    performance by resulting in disk cache getting kicked out, or even driving
    the system to swap.
    
    Bug #20766.

diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c
index 70d0c85..737ceae 100644
--- a/libdrm/intel/intel_bufmgr_gem.c
+++ b/libdrm/intel/intel_bufmgr_gem.c
@@ -139,6 +139,8 @@ struct _drm_intel_bo_gem {
     uint32_t tiling_mode;
     uint32_t swizzle_mode;
 
+    time_t free_time;
+
     /** Array passed to the DRM containing relocation information. */
     struct drm_i915_gem_relocation_entry *relocs;
     /** Array of bos corresponding to relocs[i].target_handle */
@@ -220,7 +222,6 @@ drm_intel_gem_bo_bucket_for_size(drm_intel_bufmgr_gem *bufmgr_gem,
     return NULL;
 }
 
-
 static void drm_intel_gem_dump_validation_list(drm_intel_bufmgr_gem *bufmgr_gem)
 {
     int i, j;
@@ -533,6 +534,30 @@ drm_intel_gem_bo_free(drm_intel_bo *bo)
     free(bo);
 }
 
+/** Frees all cached buffers significantly older than @time. */
+static void
+drm_intel_gem_cleanup_bo_cache(drm_intel_bufmgr_gem *bufmgr_gem, time_t time)
+{
+    int i;
+
+    for (i = 0; i < DRM_INTEL_GEM_BO_BUCKETS; i++) {
+	struct drm_intel_gem_bo_bucket *bucket = &bufmgr_gem->cache_bucket[i];
+
+	while (!DRMLISTEMPTY(&bucket->head)) {
+	    drm_intel_bo_gem *bo_gem;
+
+	    bo_gem = DRMLISTENTRY(drm_intel_bo_gem, bucket->head.next, head);
+	    if (time - bo_gem->free_time <= 1)
+		break;
+
+	    DRMLISTDEL(&bo_gem->head);
+	    bucket->num_entries--;
+
+	    drm_intel_gem_bo_free(&bo_gem->bo);
+	}
+    }
+}
+
 static void
 drm_intel_gem_bo_unreference_locked(drm_intel_bo *bo)
 {
@@ -567,6 +592,11 @@ drm_intel_gem_bo_unreference_locked(drm_intel_bo *bo)
 	      bucket->num_entries < bucket->max_entries)) &&
 	    drm_intel_gem_bo_set_tiling(bo, &tiling_mode, 0) == 0)
 	{
+	    struct timespec time;
+
+	    clock_gettime(CLOCK_MONOTONIC, &time);
+	    bo_gem->free_time = time.tv_sec;
+
 	    bo_gem->name = NULL;
 	    bo_gem->validate_index = -1;
 	    bo_gem->relocs = NULL;
@@ -575,6 +605,8 @@ drm_intel_gem_bo_unreference_locked(drm_intel_bo *bo)
 
 	    DRMLISTADDTAIL(&bo_gem->head, &bucket->head);
 	    bucket->num_entries++;
+
+	    drm_intel_gem_cleanup_bo_cache(bufmgr_gem, time.tv_sec);
 	} else {
 	    drm_intel_gem_bo_free(bo);
 	}

commit 80179df5f85a2fd39b2544f1b7aae61102800f0f
Author: Dave Airlie <airlied@linux.ie>
Date:   Fri Jul 10 02:38:13 2009 +1000

    configure: move AC_USE_SYSTEM_EXTENSIONS up higher
    
    this was giving me a warning on automake 1.11

diff --git a/configure.ac b/configure.ac
index d747fe2..1db781c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,6 +20,7 @@
 
 AC_PREREQ(2.60)
 AC_INIT([libdrm], 2.4.11, [dri-devel@lists.sourceforge.net], libdrm)
+AC_USE_SYSTEM_EXTENSIONS
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([dist-bzip2])
 
@@ -31,7 +32,6 @@ AC_PROG_CC
 
 AC_HEADER_STDC
 AC_SYS_LARGEFILE
-AC_USE_SYSTEM_EXTENSIONS
 
 PKG_CHECK_MODULES(PTHREADSTUBS, pthread-stubs)
 AC_SUBST(PTHREADSTUBS_CFLAGS)

commit f257201c11fd1aff9319aaf47556b184141ac7cb
Author: Ben Skeggs <bskeggs@redhat.com>
Date:   Thu Jul 9 11:41:47 2009 +1000

    nouveau: fix pin for buffers created with bo_wrap

diff --git a/libdrm/nouveau/nouveau_bo.c b/libdrm/nouveau/nouveau_bo.c
index e68533b..fea3a7d 100644
--- a/libdrm/nouveau/nouveau_bo.c
+++ b/libdrm/nouveau/nouveau_bo.c
@@ -752,11 +752,13 @@ nouveau_bo_pin(struct nouveau_bo *bo, uint32_t flags)
 		return nouveau_bo_pin_nomm(bo, flags);
 
 	/* Ensure we have a kernel object... */
-	if (!nvbo->handle) {
+	if (!nvbo->flags) {
 		if (!(flags & (NOUVEAU_BO_VRAM | NOUVEAU_BO_GART)))
 			return -EINVAL;
 		nvbo->flags = flags;
+	}
 
+	if (!nvbo->handle) {
 		ret = nouveau_bo_kalloc(nvbo, NULL);
 		if (ret)
 			return ret;

commit 4179c5f0a69b452cf94a507c13021e4918a3e02d
Author: Ian Romanick <ian.d.romanick@intel.com>
Date:   Mon Jul 6 15:36:20 2009 -0700

    s/AC_USE_SYSTEM_MACROS/AC_USE_SYSTEM_EXTENSIONS/
    
    Not sure what I was thinking.

diff --git a/configure.ac b/configure.ac
index 1c20398..d747fe2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,7 +31,7 @@ AC_PROG_CC
 
 AC_HEADER_STDC
 AC_SYS_LARGEFILE
-AC_USE_SYSTEM_MACROS
+AC_USE_SYSTEM_EXTENSIONS
 
 PKG_CHECK_MODULES(PTHREADSTUBS, pthread-stubs)
 AC_SUBST(PTHREADSTUBS_CFLAGS)

commit c5a5bbbe899400642795c1d95aef78deade9241f
Author: Pauli Nieminen <suokkos@gmail.com>
Date:   Mon Jul 6 23:37:20 2009 +0300

    libdrm: Make chown check for return value
    
    If call was interrupted by signal we have to make call again.
    
    Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>

diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c
index 1a5cee4..26dd812 100644
--- a/libdrm/xf86drm.c
+++ b/libdrm/xf86drm.c
@@ -270,6 +270,36 @@ static int drmMatchBusID(const char *id1, const char *id2)
 }
 
 /**
+ * Handles error checking for chown call.
+ *
+ * \param path to file.
+ * \param id of the new owner.
+ * \param id of the new group.
+ *
+ * \return zero if success or -1 if failure.
+ *
+ * \internal
+ * Checks for failure. If failure was caused by signal call chown again.
+ * If any other failure happened then it will output error mesage using
+ * drmMsg() call.
+ */
+static int chown_check_return(const char *path, uid_t owner, gid_t group)
+{
+	int rv;
+
+	do {
+		rv = chown(path, owner, group);
+	} while (rv != 0 && errno == EINTR);
+
+	if (rv == 0)
+		return 0;
+
+	drmMsg("Failed to change owner or group for file %s! %d: %s\n",
+			path, errno, strerror(errno));
+	return -1;
+}
+
+/**
  * Open the DRM device, creating it if necessary.
  *
  * \param dev major and minor numbers of the device.
@@ -307,7 +337,7 @@ static int drmOpenDevice(long dev, int minor, int type)
 	if (!isroot)
 	    return DRM_ERR_NOT_ROOT;
 	mkdir(DRM_DIR_NAME, DRM_DEV_DIRMODE);
-	chown(DRM_DIR_NAME, 0, 0); /* root:root */
+	chown_check_return(DRM_DIR_NAME, 0, 0); /* root:root */
 	chmod(DRM_DIR_NAME, DRM_DEV_DIRMODE);
     }
 
@@ -320,7 +350,7 @@ static int drmOpenDevice(long dev, int minor, int type)
     }
 
     if (drm_server_info) {
-	chown(buf, user, group);
+	chown_check_return(buf, user, group);
 	chmod(buf, devmode);
     }
 #else
@@ -363,7 +393,7 @@ wait_for_udev:
 	remove(buf);
 	mknod(buf, S_IFCHR | devmode, dev);
 	if (drm_server_info) {
-	    chown(buf, user, group);
+	    chown_check_return(buf, user, group);
 	    chmod(buf, devmode);
 	}
     }

commit a953b3270cef52dd2de70cc6aa08687af9d57815
Author: Ian Romanick <ian.d.romanick@intel.com>
Date:   Mon Jul 6 13:23:46 2009 -0700

    libdrm: Set _XOPEN_SOURCE and _GNU_SOURCE
    
    Several POSIX extensions are used in the libdrm code (e.g., mknod and ffs).
    Set _XOPEN_SOURCE and _GNU_SOURCE to something reasonable to ensure that
    prototypes for these functions are available.  This is done in configure.ac
    using AC_USE_SYSTEM_MACROS.  This requires autoconf 2.60 or later.  Eventually
    the code should check for the existance of these defines and do something
    reasonable if they are not available.
    
    Inspired by a patch by Pauli Nieminen and suggestions from Julien Cristau.
    Thanks.
    
    Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>

diff --git a/configure.ac b/configure.ac
index be2fbbf..1c20398 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,7 +18,7 @@
 #  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 #  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-AC_PREREQ(2.57)
+AC_PREREQ(2.60)
 AC_INIT([libdrm], 2.4.11, [dri-devel@lists.sourceforge.net], libdrm)
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([dist-bzip2])
@@ -31,6 +31,7 @@ AC_PROG_CC
 
 AC_HEADER_STDC
 AC_SYS_LARGEFILE
+AC_USE_SYSTEM_MACROS
 
 PKG_CHECK_MODULES(PTHREADSTUBS, pthread-stubs)
 AC_SUBST(PTHREADSTUBS_CFLAGS)
@@ -145,7 +146,6 @@ if test "x$HAVE_LIBUDEV" = xyes; then
 fi
 AM_CONDITIONAL(HAVE_LIBUDEV, [test "x$HAVE_LIBUDEV" = xyes])
 
-
 AC_SUBST(WARN_CFLAGS)
 AC_OUTPUT([
 	Makefile

commit 78fa590a1d297f2e2fea98bd3f0cbf4cdb1e3a08
Author: Eric Anholt <eric@anholt.net>
Date:   Mon Jul 6 11:55:28 2009 -0700

    intel: Fix up math errors when allocating very large BOs.
    
    The logbase2 would overflow and wrap the size around to 0, making the code
    allocate a 4kb object instead.  By simplifying the code to just walk the
    14-entry bucket array comparing sizes instead of indexing on
    ffs(1 << logbase2(size)), we avoid silly math errors and have code of
    approximately the same speed.
    
    Many thanks to Simon Farnsworth for debugging and providing a working patch.
    Bug #27365.

diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c
index e88a6c3..70d0c85 100644
--- a/libdrm/intel/intel_bufmgr_gem.c
+++ b/libdrm/intel/intel_bufmgr_gem.c
@@ -78,6 +78,7 @@ struct drm_intel_gem_bo_bucket {
     */
    int max_entries;
    int num_entries;
+   unsigned long size;
 };
 
 /* Only cache objects up to 64MB.  Bigger than that, and the rounding of the
@@ -203,39 +204,20 @@ drm_intel_gem_bo_set_tiling(drm_intel_bo *bo, uint32_t *tiling_mode,
 static void
 drm_intel_gem_bo_unreference(drm_intel_bo *bo);
 
-static int
-logbase2(int n)
-{
-   int i = 1;
-   int log2 = 0;
-
-   while (n > i) {
-      i *= 2;
-      log2++;
-   }
-
-   return log2;
-}
-
 static struct drm_intel_gem_bo_bucket *
 drm_intel_gem_bo_bucket_for_size(drm_intel_bufmgr_gem *bufmgr_gem,
 				 unsigned long size)
 {
     int i;
 
-    /* We only do buckets in power of two increments */
-    if ((size & (size - 1)) != 0)
-	return NULL;
-
-    /* We should only see sizes rounded to pages. */
-    assert((size % 4096) == 0);
-
-    /* We always allocate in units of pages */
-    i = ffs(size / 4096) - 1;
-    if (i >= DRM_INTEL_GEM_BO_BUCKETS)
-	return NULL;
+    for (i = 0; i < DRM_INTEL_GEM_BO_BUCKETS; i++) {
+	struct drm_intel_gem_bo_bucket *bucket = &bufmgr_gem->cache_bucket[i];
+	if (bucket->size >= size) {
+	    return bucket;
+	}
+    }
 
-    return &bufmgr_gem->cache_bucket[i];
+    return NULL;
 }
 
 
@@ -345,10 +327,7 @@ drm_intel_gem_bo_alloc_internal(drm_intel_bufmgr *bufmgr, const char *name,
     unsigned long bo_size;
 
     /* Round the allocated size up to a power of two number of pages. */
-    bo_size = 1 << logbase2(size);
-    if (bo_size < page_size)
-	bo_size = page_size;
-    bucket = drm_intel_gem_bo_bucket_for_size(bufmgr_gem, bo_size);
+    bucket = drm_intel_gem_bo_bucket_for_size(bufmgr_gem, size);
 
     /* If we don't have caching at this size, don't actually round the
      * allocation up.
@@ -357,6 +336,8 @@ drm_intel_gem_bo_alloc_internal(drm_intel_bufmgr *bufmgr, const char *name,
 	bo_size = size;
 	if (bo_size < page_size)
 	    bo_size = page_size;
+    } else {
+	bo_size = bucket->size;
     }
 
     pthread_mutex_lock(&bufmgr_gem->lock);
@@ -1412,6 +1393,7 @@ drm_intel_bufmgr_gem_init(int fd, int batch_size)
     struct drm_i915_gem_get_aperture aperture;
     drm_i915_getparam_t gp;
     int ret, i;
+    unsigned long size;
 
     bufmgr_gem = calloc(1, sizeof(*bufmgr_gem));
     bufmgr_gem->fd = fd;
@@ -1483,8 +1465,10 @@ drm_intel_bufmgr_gem_init(int fd, int batch_size)
     bufmgr_gem->bufmgr.bo_disable_reuse = drm_intel_gem_bo_disable_reuse;
     bufmgr_gem->bufmgr.get_pipe_from_crtc_id = drm_intel_gem_get_pipe_from_crtc_id;
     /* Initialize the linked lists for BO reuse cache. */
-    for (i = 0; i < DRM_INTEL_GEM_BO_BUCKETS; i++)
+    for (i = 0, size = 4096; i < DRM_INTEL_GEM_BO_BUCKETS; i++, size *= 2) {
 	DRMINITLISTHEAD(&bufmgr_gem->cache_bucket[i].head);
+	bufmgr_gem->cache_bucket[i].size = size;
+    }
 
     return &bufmgr_gem->bufmgr;
 }

commit cea2d29ee49f23d560f0088a1a3dd01932a1eaf4
Author: Edward O'Callaghan <eocallaghan@auroraux.org>
Date:   Thu Jul 2 11:03:48 2009 -0700

    intel: fix compiler warning about returning a void value.
    
    bug #21999

diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c
index c25fc4c..e88a6c3 100644
--- a/libdrm/intel/intel_bufmgr_gem.c
+++ b/libdrm/intel/intel_bufmgr_gem.c
@@ -867,7 +867,7 @@ drm_intel_gem_bo_get_subdata (drm_intel_bo *bo, unsigned long offset,
 static void
 drm_intel_gem_bo_wait_rendering(drm_intel_bo *bo)
 {
-    return drm_intel_gem_bo_start_gtt_access(bo, 0);
+    drm_intel_gem_bo_start_gtt_access(bo, 0);
 }
 
 /**

commit 90ae0f2bb8d53500f5c9d06e2dc1a18d5a5d0cf5
Author: Pauli Nieminen <suokkos@gmail.com>
Date:   Sat Jul 4 02:18:51 2009 +0300

    libdrm: Fix pci id numbers to unsigned so code won't mix signed/unsigned integers.

diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c
index 2b1604b..1a5cee4 100644
--- a/libdrm/xf86drm.c
+++ b/libdrm/xf86drm.c
@@ -241,22 +241,22 @@ static int drmMatchBusID(const char *id1, const char *id2)
 
     /* Try to match old/new-style PCI bus IDs. */
     if (strncasecmp(id1, "pci", 3) == 0) {
-	int o1, b1, d1, f1;
-	int o2, b2, d2, f2;
+	unsigned int o1, b1, d1, f1;
+	unsigned int o2, b2, d2, f2;
 	int ret;
 
-	ret = sscanf(id1, "pci:%04x:%02x:%02x.%d", &o1, &b1, &d1, &f1);
+	ret = sscanf(id1, "pci:%04x:%02x:%02x.%u", &o1, &b1, &d1, &f1);
 	if (ret != 4) {
 	    o1 = 0;
-	    ret = sscanf(id1, "PCI:%d:%d:%d", &b1, &d1, &f1);
+	    ret = sscanf(id1, "PCI:%u:%u:%u", &b1, &d1, &f1);
 	    if (ret != 3)
 		return 0;
 	}
 
-	ret = sscanf(id2, "pci:%04x:%02x:%02x.%d", &o2, &b2, &d2, &f2);
+	ret = sscanf(id2, "pci:%04x:%02x:%02x.%u", &o2, &b2, &d2, &f2);
 	if (ret != 4) {
 	    o2 = 0;
-	    ret = sscanf(id2, "PCI:%d:%d:%d", &b2, &d2, &f2);
+	    ret = sscanf(id2, "PCI:%u:%u:%u", &b2, &d2, &f2);
 	    if (ret != 3)
 		return 0;
 	}

commit 015efd1bfa72ab8b80cc45f11eb22d7f1a1085f7
Author: Ian Romanick <ian.d.romanick@intel.com>
Date:   Mon Jul 6 09:23:59 2009 -0700

    strcasecmp is in strings.h.
    
    Based on patch by Pauli Nieminen.  Thanks.

diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c
index 55df19a..2b1604b 100644
--- a/libdrm/xf86drm.c
+++ b/libdrm/xf86drm.c
@@ -38,6 +38,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <strings.h>
 #include <ctype.h>
 #include <fcntl.h>
 #include <errno.h>

commit 3dda0050f16ddb4a64e66c80aebecea5383c72f1
Author: Pauli Nieminen <suokkos@gmail.com>
Date:   Sat Jul 4 02:18:49 2009 +0300

    libdrm: Remove typedef for non-existing enum

diff --git a/shared-core/drm.h b/shared-core/drm.h
index 7758af4..42a6c23 100644
--- a/shared-core/drm.h
+++ b/shared-core/drm.h
@@ -855,7 +855,6 @@ typedef struct drm_set_version drm_set_version_t;
 typedef struct drm_fence_arg drm_fence_arg_t;
 typedef struct drm_mm_type_arg drm_mm_type_arg_t;
 typedef struct drm_mm_init_arg drm_mm_init_arg_t;
-typedef enum drm_bo_type drm_bo_type_t;
 #endif
 
 #endif

commit 39970c67b77014caac9a4c3a33765ac7a312b54e
Author: Dave Airlie <airlied@redhat.com>
Date:   Mon Jul 6 13:34:24 2009 +1000

    radeon: move cs space checking code to libdrm_radeon.
    
    This ports a lot of the space checking code into a the common
    library, so that the DDX and mesa can use it.

diff --git a/libdrm/radeon/Makefile.am b/libdrm/radeon/Makefile.am
index bc8a5b8..bec1beb 100644
--- a/libdrm/radeon/Makefile.am
+++ b/libdrm/radeon/Makefile.am
@@ -37,6 +37,7 @@ libdrm_radeon_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@
 libdrm_radeon_la_SOURCES = \
 	radeon_bo_gem.c \
 	radeon_cs_gem.c \
+	radeon_cs_space.c \
 	radeon_track.c
 
 libdrm_radeonincludedir = ${includedir}/drm
diff --git a/libdrm/radeon/radeon_bo.h b/libdrm/radeon/radeon_bo.h
index 3cabdfc..597d0ef 100644
--- a/libdrm/radeon/radeon_bo.h
+++ b/libdrm/radeon/radeon_bo.h
@@ -68,6 +68,7 @@ struct radeon_bo_funcs {
     int (*bo_map)(struct radeon_bo *bo, int write);
     int (*bo_unmap)(struct radeon_bo *bo);
     int (*bo_wait)(struct radeon_bo *bo);
+    int (*bo_is_static)(struct radeon_bo *bo);
 };
 
 struct radeon_bo_manager {
@@ -161,6 +162,13 @@ static inline int _radeon_bo_wait(struct radeon_bo *bo,
     return bo->bom->funcs->bo_wait(bo);
 }
 
+static inline int radeon_bo_is_static(struct radeon_bo *bo)
+{
+    if (bo->bom->funcs->bo_is_static)
+	return bo->bom->funcs->bo_is_static(bo);
+    return 0;
+}
+
 #define radeon_bo_open(bom, h, s, a, d, f)\
     _radeon_bo_open(bom, h, s, a, d, f, __FILE__, __FUNCTION__, __LINE__)
 #define radeon_bo_ref(bo)\
diff --git a/libdrm/radeon/radeon_bo_gem.c b/libdrm/radeon/radeon_bo_gem.c
index 05d4409..558b93a 100644
--- a/libdrm/radeon/radeon_bo_gem.c
+++ b/libdrm/radeon/radeon_bo_gem.c
@@ -204,7 +204,8 @@ static struct radeon_bo_funcs bo_gem_funcs = {
     bo_unref,
     bo_map,
     bo_unmap,
-    bo_wait
+    bo_wait,
+    NULL,
 };
 
 struct radeon_bo_manager *radeon_bo_manager_gem_ctor(int fd)
diff --git a/libdrm/radeon/radeon_cs.h b/libdrm/radeon/radeon_cs.h
index d870961..7efec7e 100644
--- a/libdrm/radeon/radeon_cs.h
+++ b/libdrm/radeon/radeon_cs.h
@@ -57,6 +57,8 @@ struct radeon_cs_space_check {
     uint32_t new_accounted;
 };
 
+#define MAX_SPACE_BOS (32)
+
 struct radeon_cs_manager;
 
 struct radeon_cs {
@@ -73,7 +75,10 @@ struct radeon_cs {
     const char                  *section_file;
     const char                  *section_func;
     int                         section_line;
-
+    struct radeon_cs_space_check bos[MAX_SPACE_BOS];
+    int                         bo_count;
+    void                        (*space_flush_fn)(void *);
+    void                        *space_flush_data;
 };
 
 /* cs functions */
@@ -99,16 +104,14 @@ struct radeon_cs_funcs {
     int (*cs_erase)(struct radeon_cs *cs);
     int (*cs_need_flush)(struct radeon_cs *cs);
     void (*cs_print)(struct radeon_cs *cs, FILE *file);
-    int (*cs_space_check)(struct radeon_cs *cs, struct radeon_cs_space_check *bos,
-			  int num_bo);
 };
 
 struct radeon_cs_manager {
     struct radeon_cs_funcs  *funcs;
     int                     fd;
-    uint32_t vram_limit, gart_limit;
-    uint32_t vram_write_used, gart_write_used;
-    uint32_t read_used;
+    int32_t vram_limit, gart_limit;
+    int32_t vram_write_used, gart_write_used;
+    int32_t read_used;
 };
 
 static inline struct radeon_cs *radeon_cs_create(struct radeon_cs_manager *csm,
@@ -172,13 +175,6 @@ static inline void radeon_cs_print(struct radeon_cs *cs, FILE *file)
     cs->csm->funcs->cs_print(cs, file);
 }
 
-static inline int radeon_cs_space_check(struct radeon_cs *cs,
-					    struct radeon_cs_space_check *bos,
-					    int num_bo)
-{
-    return cs->csm->funcs->cs_space_check(cs, bos, num_bo);
-}
-
 static inline void radeon_cs_set_limit(struct radeon_cs *cs, uint32_t domain, uint32_t limit)
 {
     
@@ -205,4 +201,37 @@ static inline void radeon_cs_write_qword(struct radeon_cs *cs, uint64_t qword)
     }
 }
 
+static inline void radeon_cs_space_set_flush(struct radeon_cs *cs, void (*fn)(void *), void *data)
+{
+    cs->space_flush_fn = fn;
+    cs->space_flush_data = data;
+}
+
+
+/*
+ * add a persistent BO to the list
+ * a persistent BO is one that will be referenced across flushes,
+ * i.e. colorbuffer, textures etc.
+ * They get reset when a new "operation" happens, where an operation
+ * is a state emission with a color/textures etc followed by a bunch of vertices.
+ */
+void radeon_cs_space_add_persistent_bo(struct radeon_cs *cs,
+				       struct radeon_bo *bo,
+				       uint32_t read_domains,
+				       uint32_t write_domain);
+
+/* reset the persistent BO list */
+void radeon_cs_space_reset_bos(struct radeon_cs *cs);
+
+/* do a space check with the current persistent BO list */
+int radeon_cs_space_check(struct radeon_cs *cs);
+
+/* do a space check with the current persistent BO list and a temporary BO
+ * a temporary BO is like a DMA buffer, which  gets flushed with the
+ * command buffer */
+int radeon_cs_space_check_with_bo(struct radeon_cs *cs,
+				  struct radeon_bo *bo,
+				  uint32_t read_domains,
+				  uint32_t write_domain);
+
 #endif
diff --git a/libdrm/radeon/radeon_cs_gem.c b/libdrm/radeon/radeon_cs_gem.c
index e06f222..264b067 100644
--- a/libdrm/radeon/radeon_cs_gem.c
+++ b/libdrm/radeon/radeon_cs_gem.c
@@ -423,99 +423,7 @@ static void cs_gem_print(struct radeon_cs *cs, FILE *file)
     }
 }
 
-static int cs_gem_check_space(struct radeon_cs *cs, struct radeon_cs_space_check *bos, int num_bo)
-{
-    struct radeon_cs_manager *csm = cs->csm;
-    int this_op_read = 0, this_op_gart_write = 0, this_op_vram_write = 0;
-    uint32_t read_domains, write_domain;
-    int i;
-    struct radeon_bo *bo;
-
-    /* check the totals for this operation */
-
-    if (num_bo == 0)
-        return 0;
-
-    /* prepare */
-    for (i = 0; i < num_bo; i++) {
-      bo = bos[i].bo;
-
-      bos[i].new_accounted = 0;
-      read_domains = bos[i].read_domains;
-      write_domain = bos[i].write_domain;
-		
-      /* already accounted this bo */
-      if (write_domain && (write_domain == bo->space_accounted)) {
-	      bos[i].new_accounted = bo->space_accounted;
-	      continue;
-      }
-      if (read_domains && ((read_domains << 16) == bo->space_accounted)) {
-	      bos[i].new_accounted = bo->space_accounted;
-	      continue;
-      }
-      
-      if (bo->space_accounted == 0) {
-	  if (write_domain == RADEON_GEM_DOMAIN_VRAM)
-	      this_op_vram_write += bo->size;
-	  else if (write_domain == RADEON_GEM_DOMAIN_GTT)
-	      this_op_gart_write += bo->size;
-	  else
-	      this_op_read += bo->size;
-	  bos[i].new_accounted = (read_domains << 16) | write_domain;
-      } else {
-	  uint16_t old_read, old_write;
-	  
-	  old_read = bo->space_accounted >> 16;
-	  old_write = bo->space_accounted & 0xffff;
-
-	  if (write_domain && (old_read & write_domain)) {
-	      bos[i].new_accounted = write_domain;
-	      /* moving from read to a write domain */
-	      if (write_domain == RADEON_GEM_DOMAIN_VRAM) {
-		  this_op_read -= bo->size;
-		  this_op_vram_write += bo->size;
-	      } else if (write_domain == RADEON_GEM_DOMAIN_VRAM) {
-		  this_op_read -= bo->size;
-		  this_op_gart_write += bo->size;
-	      }
-	  } else if (read_domains & old_write) {
-	      bos[i].new_accounted = bo->space_accounted & 0xffff;
-	  } else {
-	      /* rewrite the domains */
-	      if (write_domain != old_write)
-		  fprintf(stderr,"WRITE DOMAIN RELOC FAILURE 0x%x %d %d\n", bo->handle, write_domain, old_write);
-	      if (read_domains != old_read)
-		  fprintf(stderr,"READ DOMAIN RELOC FAILURE 0x%x %d %d\n", bo->handle, read_domains, old_read);
-	      return RADEON_CS_SPACE_FLUSH;
-	  }
-      }
-    }
-	
-    if (this_op_read < 0)
-	    this_op_read = 0;
-
-    /* check sizes - operation first */
-    if ((this_op_read + this_op_gart_write > csm->gart_limit) ||
-	(this_op_vram_write > csm->vram_limit)) {
-	    return RADEON_CS_SPACE_OP_TO_BIG;
-    }
-    
-    if (((csm->vram_write_used + this_op_vram_write) > csm->vram_limit) ||
-	((csm->read_used + csm->gart_write_used + this_op_gart_write + this_op_read) > csm->gart_limit)) {
-	    return RADEON_CS_SPACE_FLUSH;
-    }
-    
-    csm->gart_write_used += this_op_gart_write;
-    csm->vram_write_used += this_op_vram_write;
-    csm->read_used += this_op_read;
-    /* commit */
-    for (i = 0; i < num_bo; i++) {
-	    bo = bos[i].bo;
-	    bo->space_accounted = bos[i].new_accounted;
-    }
-    
-    return RADEON_CS_SPACE_OK;
-}
+
 
 static struct radeon_cs_funcs radeon_cs_gem_funcs = {
     cs_gem_create,
@@ -527,7 +435,6 @@ static struct radeon_cs_funcs radeon_cs_gem_funcs = {
     cs_gem_erase,
     cs_gem_need_flush,
     cs_gem_print,
-    cs_gem_check_space,
 };
 
 struct radeon_cs_manager *radeon_cs_manager_gem_ctor(int fd)
diff --git a/libdrm/radeon/radeon_cs_space.c b/libdrm/radeon/radeon_cs_space.c
new file mode 100644
index 0000000..5d0fe5c
--- /dev/null
+++ b/libdrm/radeon/radeon_cs_space.c
@@ -0,0 +1,234 @@
+/* 
+ * Copyright © 2009 Red Hat Inc.
+ * All Rights Reserved.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
+ * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ */
+/*
+ */
+#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
+#include "radeon_cs.h"
+
+struct rad_sizes {
+    int32_t op_read;
+    int32_t op_gart_write;
+    int32_t op_vram_write;
+};
+
+static inline int radeon_cs_setup_bo(struct radeon_cs_space_check *sc, struct rad_sizes *sizes)
+{
+    uint32_t read_domains, write_domain;
+    struct radeon_bo *bo;
+
+    bo = sc->bo;
+    sc->new_accounted = 0;
+    read_domains = sc->read_domains;
+    write_domain = sc->write_domain;
+
+    /* legacy needs a static check */
+    if (radeon_bo_is_static(bo)) {
+	bo->space_accounted = sc->new_accounted = (read_domains << 16) | write_domain;
+	return 0;
+    }
+
+    /* already accounted this bo */
+    if (write_domain && (write_domain == bo->space_accounted)) {
+	sc->new_accounted = bo->space_accounted;
+	return 0;
+    }
+    if (read_domains && ((read_domains << 16) == bo->space_accounted)) {
+	sc->new_accounted = bo->space_accounted;
+	return 0;
+    }
+
+    if (bo->space_accounted == 0) {
+	if (write_domain == RADEON_GEM_DOMAIN_VRAM)
+	    sizes->op_vram_write += bo->size;
+	else if (write_domain == RADEON_GEM_DOMAIN_GTT)
+	  sizes->op_gart_write += bo->size;
+	else
+	    sizes->op_read += bo->size;
+	sc->new_accounted = (read_domains << 16) | write_domain;
+    } else {
+	uint16_t old_read, old_write;
+	
+	old_read = bo->space_accounted >> 16;
+	old_write = bo->space_accounted & 0xffff;
+	
+	if (write_domain && (old_read & write_domain)) {
+	    sc->new_accounted = write_domain;
+	    /* moving from read to a write domain */
+	    if (write_domain == RADEON_GEM_DOMAIN_VRAM) {
+		sizes->op_read -= bo->size;
+		sizes->op_vram_write += bo->size;
+	    } else if (write_domain == RADEON_GEM_DOMAIN_VRAM) {
+		sizes->op_read -= bo->size;
+		sizes->op_gart_write += bo->size;
+	    }
+	} else if (read_domains & old_write) {
+	    sc->new_accounted = bo->space_accounted & 0xffff;
+	} else {
+	    /* rewrite the domains */
+	    if (write_domain != old_write)
+		fprintf(stderr,"WRITE DOMAIN RELOC FAILURE 0x%x %d %d\n", bo->handle, write_domain, old_write);
+	    if (read_domains != old_read)
+		fprintf(stderr,"READ DOMAIN RELOC FAILURE 0x%x %d %d\n", bo->handle, read_domains, old_read);
+	    return RADEON_CS_SPACE_FLUSH;
+	}
+    }
+    return 0;
+}
+
+static int radeon_cs_do_space_check(struct radeon_cs *cs, struct radeon_cs_space_check *new_tmp)
+{
+    struct radeon_cs_manager *csm = cs->csm;
+    int i;
+    struct radeon_bo *bo;
+    struct rad_sizes sizes;
+    int ret;
+
+    /* check the totals for this operation */
+
+    if (cs->bo_count == 0 && !new_tmp)
+	return 0;
+
+    memset(&sizes, 0, sizeof(struct rad_sizes));
+
+    /* prepare */
+    for (i = 0; i < cs->bo_count; i++) {
+	ret = radeon_cs_setup_bo(&cs->bos[i], &sizes);
+	if (ret)
+	    return ret;
+    }
+
+    if (new_tmp) {
+	ret = radeon_cs_setup_bo(new_tmp, &sizes);
+	if (ret)
+	    return ret;
+    }


Reply to: