All of lore.kernel.org
 help / color / mirror / Atom feed
From: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Matthew Auld <matthew.auld@intel.com>
Subject: [PATCH 3/3] drm/i915/dmabuf: Implement pread() callback
Date: Wed, 23 Oct 2019 09:50:39 +0200	[thread overview]
Message-ID: <20191023075039.21740-3-janusz.krzysztofik@linux.intel.com> (raw)
In-Reply-To: <20191023075039.21740-1-janusz.krzysztofik@linux.intel.com>

We need dmabuf specific pread() callback utilizing dma-buf API,
otherwise GEM_PREAD IOCTL will no longer work with dma-buf backed
(i.e., PRIME imported) objects on hardware with no mappable aperture.

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 55 ++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
index 93eea1031c82..207dbf044296 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
@@ -248,6 +248,60 @@ static void i915_gem_object_put_pages_dmabuf(struct drm_i915_gem_object *obj,
 				 DMA_BIDIRECTIONAL);
 }
 
+static int i915_gem_object_pread_dmabuf(struct drm_i915_gem_object *obj,
+					const struct drm_i915_gem_pread *args)
+{
+	struct dma_buf *dmabuf = obj->base.import_attach->dmabuf;
+	void __user *user_data = u64_to_user_ptr(args->data_ptr);
+	struct file *file = dmabuf->file;
+	const struct file_operations *fop = file->f_op;
+	void __force *vaddr;
+	int ret;
+
+	if (fop->read) {
+		loff_t offset = args->offset;
+
+		/*
+		 * fop->read() is supposed to call dma_buf_begin_cpu_access()
+		 * if O_SYNC flag is set, avoid calling it twice
+		 */
+		if (!(file->f_flags & O_SYNC)) {
+			ret = dma_buf_begin_cpu_access(dmabuf, DMA_FROM_DEVICE);
+			if (ret)
+				return ret;
+		}
+
+		ret = fop->read(file, user_data, args->size, &offset);
+
+		if (!(file->f_flags & O_SYNC))
+			dma_buf_end_cpu_access(dmabuf, DMA_FROM_DEVICE);
+
+		if (!ret)
+			return 0;
+	}
+
+	/* dma-buf file .read() not supported or failed, try dma_buf_vmap() */
+	ret = dma_buf_begin_cpu_access(dmabuf, DMA_FROM_DEVICE);
+	if (ret)
+		return ret;
+
+	vaddr = dma_buf_vmap(dmabuf);
+	if (!vaddr)
+		goto out_err;
+
+	ret = copy_to_user(user_data, vaddr + args->offset, args->size);
+	dma_buf_vunmap(dmabuf, vaddr);
+	if (!ret)
+		goto out_end;
+
+out_err:
+	/* fall back to GTT mapping */
+	ret = -ENODEV;
+out_end:
+	dma_buf_end_cpu_access(dmabuf, DMA_FROM_DEVICE);
+	return ret;
+}
+
 static int i915_gem_object_pwrite_dmabuf(struct drm_i915_gem_object *obj,
 					 const struct drm_i915_gem_pwrite *args)
 {
@@ -305,6 +359,7 @@ static int i915_gem_object_pwrite_dmabuf(struct drm_i915_gem_object *obj,
 static const struct drm_i915_gem_object_ops i915_gem_object_dmabuf_ops = {
 	.get_pages = i915_gem_object_get_pages_dmabuf,
 	.put_pages = i915_gem_object_put_pages_dmabuf,
+	.pread = i915_gem_object_pread_dmabuf,
 	.pwrite = i915_gem_object_pwrite_dmabuf,
 };
 
-- 
2.21.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2019-10-23  7:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-23  7:50 [PATCH 1/3] drm/i915/dmabuf: Implement pwrite() callback Janusz Krzysztofik
2019-10-23  7:50 ` [PATCH 2/3] drm/i915: Add vfunc for pread Janusz Krzysztofik
2019-10-23  7:50 ` Janusz Krzysztofik [this message]
2019-10-23  8:41 ` ✓ Fi.CI.BAT: success for series starting with [1/3] drm/i915/dmabuf: Implement pwrite() callback Patchwork
2019-10-23 23:34 ` ✓ Fi.CI.IGT: " Patchwork
2019-10-23 23:34   ` [Intel-gfx] " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191023075039.21740-3-janusz.krzysztofik@linux.intel.com \
    --to=janusz.krzysztofik@linux.intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=matthew.auld@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.