]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/libdrm.git/blobdiff - radeon/radeon_bo_gem.c
libdrm_radeon: Optimize cs_gem_reloc to do less looping.
[glsdk/libdrm.git] / radeon / radeon_bo_gem.c
index 9bf119a6444a1981a7048b4acc77917548ab640c..081ccb9ffc1244b51252f68b561050e1b2904d47 100644 (file)
@@ -1,8 +1,8 @@
-/* 
+/*
  * Copyright © 2008 Dave Airlie
  * Copyright © 2008 Jérôme Glisse
  * 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
  * 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 
+ * 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
@@ -39,6 +39,7 @@
 #include <sys/mman.h>
 #include <errno.h>
 #include "xf86drm.h"
+#include "xf86atomic.h"
 #include "drm.h"
 #include "radeon_drm.h"
 #include "radeon_bo.h"
@@ -49,6 +50,7 @@ struct radeon_bo_gem {
     struct radeon_bo_int base;
     uint32_t            name;
     int                 map_count;
+    atomic_t            reloc_in_cs;
     void *priv_ptr;
 };
 
@@ -80,6 +82,7 @@ static struct radeon_bo *bo_open(struct radeon_bo_manager *bom,
     bo->base.domains = domains;
     bo->base.flags = flags;
     bo->base.ptr = NULL;
+    atomic_set(&bo->reloc_in_cs, 0);
     bo->map_count = 0;
     if (handle) {
         struct drm_gem_open open_arg;
@@ -156,7 +159,7 @@ static int bo_map(struct radeon_bo_int *boi, int write)
         return 0;
     }
     if (bo_gem->priv_ptr) {
-       goto wait;
+        goto wait;
     }
 
     boi->ptr = NULL;
@@ -223,14 +226,14 @@ static int bo_is_busy(struct radeon_bo_int *boi, uint32_t *domain)
     args.domain = 0;
 
     ret = drmCommandWriteRead(boi->bom->fd, DRM_RADEON_GEM_BUSY,
-                             &args, sizeof(args));
+                              &args, sizeof(args));
 
     *domain = args.domain;
     return ret;
 }
 
 static int bo_set_tiling(struct radeon_bo_int *boi, uint32_t tiling_flags,
-                        uint32_t pitch)
+                         uint32_t pitch)
 {
     struct drm_radeon_gem_set_tiling args;
     int r;
@@ -240,14 +243,14 @@ static int bo_set_tiling(struct radeon_bo_int *boi, uint32_t tiling_flags,
     args.pitch = pitch;
 
     r = drmCommandWriteRead(boi->bom->fd,
-                           DRM_RADEON_GEM_SET_TILING,
-                           &args,
-                           sizeof(args));
+                            DRM_RADEON_GEM_SET_TILING,
+                            &args,
+                            sizeof(args));
     return r;
 }
 
 static int bo_get_tiling(struct radeon_bo_int *boi, uint32_t *tiling_flags,
-                        uint32_t *pitch)
+                         uint32_t *pitch)
 {
     struct drm_radeon_gem_set_tiling args;
     int r;
@@ -255,12 +258,12 @@ static int bo_get_tiling(struct radeon_bo_int *boi, uint32_t *tiling_flags,
     args.handle = boi->handle;
 
     r = drmCommandWriteRead(boi->bom->fd,
-                           DRM_RADEON_GEM_GET_TILING,
-                           &args,
-                           sizeof(args));
+                            DRM_RADEON_GEM_GET_TILING,
+                            &args,
+                            sizeof(args));
 
     if (r)
-       return r;
+        return r;
 
     *tiling_flags = args.tiling_flags;
     *pitch = args.pitch;
@@ -309,6 +312,12 @@ uint32_t radeon_gem_name_bo(struct radeon_bo *bo)
     return bo_gem->name;
 }
 
+void *radeon_gem_get_reloc_in_cs(struct radeon_bo *bo)
+{
+    struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo;
+    return &bo_gem->reloc_in_cs;
+}
+
 int radeon_gem_get_kernel_name(struct radeon_bo *bo, uint32_t *name)
 {
     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
@@ -318,7 +327,7 @@ int radeon_gem_get_kernel_name(struct radeon_bo *bo, uint32_t *name)
     flink.handle = bo->handle;
     r = drmIoctl(boi->bom->fd, DRM_IOCTL_GEM_FLINK, &flink);
     if (r) {
-       return r;
+        return r;
     }
     *name = flink.name;
     return 0;