+static struct util_hash_table *fd_tab = NULL;
+
+pipe_static_mutex(nouveau_screen_mutex);
+
+bool nouveau_drm_screen_unref(struct nouveau_screen *screen)
+{
+ int ret;
+ if (screen->refcount == -1)
+ return true;
+
+ pipe_mutex_lock(nouveau_screen_mutex);
+ ret = --screen->refcount;
+ assert(ret >= 0);
+ if (ret == 0)
+ util_hash_table_remove(fd_tab, intptr_to_pointer(screen->device->fd));
+ pipe_mutex_unlock(nouveau_screen_mutex);
+ return ret == 0;
+}
+
+static unsigned hash_fd(void *key)
+{
+ int fd = pointer_to_intptr(key);
+ struct stat stat;
+ fstat(fd, &stat);
+
+ return stat.st_dev ^ stat.st_ino ^ stat.st_rdev;
+}
+
+static int compare_fd(void *key1, void *key2)