@@ -11,7 +11,10 @@
#include <asm/smp.h>
+#include <drm/drm_file.h>
+
#include "gem/i915_gem_dmabuf.h"
+#include "i915_drm_client.h"
#include "i915_drv.h"
#include "i915_gem_object.h"
#include "i915_scatterlist.h"
@@ -344,6 +347,35 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
return ERR_PTR(ret);
}
+int i915_gem_prime_fd_to_handle(struct drm_device *dev,
+ struct drm_file *file_priv, int prime_fd,
+ uint32_t *handle)
+{
+ struct drm_gem_object *gem_obj = NULL;
+ int ret;
+
+ if (IS_ENABLED(CONFIG_PROC_FS))
+ ret = drm_gem_prime_fd_to_handle_obj(dev, file_priv, prime_fd,
+ handle, &gem_obj);
+ else
+ ret = drm_gem_prime_fd_to_handle(dev, file_priv, prime_fd,
+ handle);
+ if (ret)
+ return ret;
+
+ if (gem_obj) {
+ struct drm_i915_file_private *fpriv = file_priv->driver_priv;
+ struct drm_i915_gem_object *obj = to_intel_bo(gem_obj);
+
+ /* Really imported and not just alias? */
+ if (obj->ops == &i915_gem_object_dmabuf_ops)
+ i915_drm_client_add_object(fpriv->client, obj);
+ i915_gem_object_put(obj);
+ }
+
+ return 0;
+}
+
#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
#include "selftests/mock_dmabuf.c"
#include "selftests/i915_gem_dmabuf.c"
@@ -6,8 +6,11 @@
#ifndef __I915_GEM_DMABUF_H__
#define __I915_GEM_DMABUF_H__
+#include <linux/types.h>
+
struct drm_gem_object;
struct drm_device;
+struct drm_file;
struct dma_buf;
struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
@@ -15,4 +18,8 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int flags);
+int i915_gem_prime_fd_to_handle(struct drm_device *dev,
+ struct drm_file *file_priv, int prime_fd,
+ uint32_t *handle);
+
#endif /* __I915_GEM_DMABUF_H__ */
@@ -1806,7 +1806,7 @@ static const struct drm_driver i915_drm_driver = {
.show_fdinfo = i915_drm_client_fdinfo,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
- .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
+ .prime_fd_to_handle = i915_gem_prime_fd_to_handle,
.gem_prime_import = i915_gem_prime_import,
.dumb_create = i915_gem_dumb_create,