Merge remote-tracking branch 'origin/master' into pipe-video
[mesa.git] / src / gallium / winsys / r600 / drm / r600_drm.c
index cd0aa318be519633a444cea03df7641bbef89d21..311324f4f7135c2c3c00cf9b239fdd134cbbb847 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/ioctl.h>
 #include "util/u_inlines.h"
 #include "util/u_debug.h"
+#include "util/u_hash_table.h"
 #include <pipebuffer/pb_bufmgr.h>
 #include "r600.h"
 #include "r600_priv.h"
@@ -198,7 +199,6 @@ static int radeon_get_clock_crystal_freq(struct radeon *radeon)
        uint32_t clock_crystal_freq;
        int r;
 
-       radeon->device = 0;
        info.request = RADEON_INFO_CLOCK_CRYSTAL_FREQ;
        info.value = (uintptr_t)&clock_crystal_freq;
        r = drmCommandWriteRead(radeon->fd, DRM_RADEON_INFO, &info,
@@ -217,7 +217,6 @@ static int radeon_get_num_backends(struct radeon *radeon)
        uint32_t num_backends;
        int r;
 
-       radeon->device = 0;
        info.request = RADEON_INFO_NUM_BACKENDS;
        info.value = (uintptr_t)&num_backends;
        r = drmCommandWriteRead(radeon->fd, DRM_RADEON_INFO, &info,
@@ -242,6 +241,18 @@ static int radeon_init_fence(struct radeon *radeon)
        return 0;
 }
 
+#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
+
+static unsigned handle_hash(void *key)
+{
+    return PTR_TO_UINT(key);
+}
+
+static int handle_compare(void *key1, void *key2)
+{
+    return PTR_TO_UINT(key1) != PTR_TO_UINT(key2);
+}
+
 static struct radeon *radeon_new(int fd, unsigned device)
 {
        struct radeon *radeon;
@@ -340,6 +351,9 @@ static struct radeon *radeon_new(int fd, unsigned device)
                radeon_decref(radeon);
                return NULL;
        }
+
+       radeon->bo_handles = util_hash_table_create(handle_hash, handle_compare);
+       pipe_mutex_init(radeon->bo_handles_mutex);
        return radeon;
 }
 
@@ -356,6 +370,8 @@ struct radeon *radeon_decref(struct radeon *radeon)
                return NULL;
        }
 
+       util_hash_table_destroy(radeon->bo_handles);
+       pipe_mutex_destroy(radeon->bo_handles_mutex);
        if (radeon->fence_bo) {
                r600_bo_reference(radeon, &radeon->fence_bo, NULL);
        }
@@ -363,9 +379,6 @@ struct radeon *radeon_decref(struct radeon *radeon)
        if (radeon->bomgr)
                r600_bomgr_destroy(radeon->bomgr);
 
-       if (radeon->fd >= 0)
-               drmClose(radeon->fd);
-
        free(radeon);
        return NULL;
 }