@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
/**************************************************************************
*
- * Copyright (c) 2009-2013 VMware, Inc., Palo Alto, CA., USA
+ * Copyright (c) 2009-2022 VMware, Inc., Palo Alto, CA., USA
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -51,6 +51,7 @@
#include <linux/module.h>
#include "ttm_object.h"
#include "vmwgfx_drv.h"
+#include "vmwgfx_resource_priv.h"
MODULE_IMPORT_NS(DMA_BUF);
@@ -617,6 +618,7 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
struct ttm_base_object *base;
struct dma_buf *dma_buf;
struct ttm_prime_object *prime;
+ struct vmw_resource *res;
int ret;
base = ttm_base_object_lookup(tfile, handle);
@@ -667,6 +669,9 @@ int ttm_prime_handle_to_fd(struct ttm_object_file *tfile,
ret = dma_buf_fd(dma_buf, flags);
if (ret >= 0) {
+ res = user_surface_converter->base_obj_to_res(&prime->base);
+ if (res)
+ vmw_resource_prime_ref(res);
*prime_fd = ret;
ret = 0;
} else
@@ -853,6 +853,8 @@ void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
pgoff_t end);
int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
pgoff_t end, pgoff_t *num_prefault);
+void vmw_resource_prime_ref(struct vmw_resource *res);
+void vmw_resource_prime_unref(struct vmw_resource *res);
/**
* vmw_resource_mob_attached - Whether a resource currently has a mob attached
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
/*
- * Copyright 2021 VMware, Inc.
+ * Copyright 2021-2022 VMware, Inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@@ -46,9 +46,8 @@ vmw_buffer_object(struct ttm_buffer_object *bo)
static void vmw_gem_object_free(struct drm_gem_object *gobj)
{
struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gobj);
- if (bo) {
+ if (bo)
ttm_bo_put(bo);
- }
}
static int vmw_gem_object_open(struct drm_gem_object *obj,
@@ -158,7 +157,6 @@ int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
return ret;
}
-
int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data,
struct drm_file *filp)
{
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 OR MIT
/**************************************************************************
*
- * Copyright 2013 VMware, Inc., Palo Alto, CA., USA
+ * Copyright 2013-2022 VMware, Inc., Palo Alto, CA., USA
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
@@ -31,6 +31,7 @@
*/
#include "vmwgfx_drv.h"
+#include "vmwgfx_resource_priv.h"
#include "ttm_object.h"
#include <linux/dma-buf.h>
@@ -62,12 +63,21 @@ static void vmw_prime_unmap_dma_buf(struct dma_buf_attachment *attach,
{
}
+static void vmw_prime_release(struct dma_buf *dma_buf)
+{
+ struct ttm_prime_object *prime = dma_buf->priv;
+ struct vmw_resource *res =
+ user_surface_converter->base_obj_to_res(&prime->base);
+ if (res)
+ vmw_resource_prime_unref(res);
+}
+
const struct dma_buf_ops vmw_prime_dmabuf_ops = {
.attach = vmw_prime_map_attach,
.detach = vmw_prime_map_detach,
.map_dma_buf = vmw_prime_map_dma_buf,
.unmap_dma_buf = vmw_prime_unmap_dma_buf,
- .release = NULL,
+ .release = vmw_prime_release,
};
int vmw_prime_fd_to_handle(struct drm_device *dev,
@@ -1169,3 +1169,15 @@ int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
return 0;
}
+
+void vmw_resource_prime_ref(struct vmw_resource *res)
+{
+ if (res->backup)
+ drm_gem_object_get(&res->backup->base.base);
+}
+
+void vmw_resource_prime_unref(struct vmw_resource *res)
+{
+ if (res->backup)
+ drm_gem_object_put(&res->backup->base.base);
+}
@@ -1502,6 +1502,7 @@ vmw_gb_surface_define_internal(struct drm_device *dev,
goto out_unlock;
} else {
backup_handle = req->base.buffer_handle;
+ drm_gem_object_get(&res->backup->base.base);
}
}
} else if (req->base.drm_surface_flags &