linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: dri-devel@lists.freedesktop.org
Cc: spice-devel@redhat.com, Gerd Hoffmann <kraxel@redhat.com>,
	Dave Airlie <airlied@redhat.com>, David Airlie <airlied@linux.ie>,
	virtualization@lists.linux-foundation.org (open list:DRM DRIVER
	FOR QXL VIRTUAL GPU),
	spice-devel@lists.freedesktop.org (open list:DRM DRIVER FOR QXL
	VIRTUAL GPU), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v2 16/18] drm/qxl: implement prime kmap/kunmap
Date: Wed, 12 Dec 2018 14:21:07 +0100	[thread overview]
Message-ID: <20181212132109.8126-17-kraxel@redhat.com> (raw)
In-Reply-To: <20181212132109.8126-1-kraxel@redhat.com>

Generic fbdev emulation needs this.  Also: We must keep track of the
number of mappings now, so we don't unmap early in case two users want a
kmap of the same bo.  Add a sanity check to destroy callback to make
sure kmap/kunmap is balanced.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 drivers/gpu/drm/qxl/qxl_drv.h    |  1 +
 drivers/gpu/drm/qxl/qxl_object.c |  6 ++++++
 drivers/gpu/drm/qxl/qxl_prime.c  | 17 +++++++++++++----
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
index 43c6df9cf9..8c3af1cdbe 100644
--- a/drivers/gpu/drm/qxl/qxl_drv.h
+++ b/drivers/gpu/drm/qxl/qxl_drv.h
@@ -84,6 +84,7 @@ struct qxl_bo {
 	struct ttm_bo_kmap_obj		kmap;
 	unsigned int pin_count;
 	void				*kptr;
+	unsigned int                    map_count;
 	int                             type;
 
 	/* Constant after initialization */
diff --git a/drivers/gpu/drm/qxl/qxl_object.c b/drivers/gpu/drm/qxl/qxl_object.c
index 024c8dd317..4928fa6029 100644
--- a/drivers/gpu/drm/qxl/qxl_object.c
+++ b/drivers/gpu/drm/qxl/qxl_object.c
@@ -36,6 +36,7 @@ static void qxl_ttm_bo_destroy(struct ttm_buffer_object *tbo)
 	qdev = (struct qxl_device *)bo->gem_base.dev->dev_private;
 
 	qxl_surface_evict(qdev, bo, false);
+	WARN_ON_ONCE(bo->map_count > 0);
 	mutex_lock(&qdev->gem.mutex);
 	list_del_init(&bo->list);
 	mutex_unlock(&qdev->gem.mutex);
@@ -131,6 +132,7 @@ int qxl_bo_kmap(struct qxl_bo *bo, void **ptr)
 	if (bo->kptr) {
 		if (ptr)
 			*ptr = bo->kptr;
+		bo->map_count++;
 		return 0;
 	}
 	r = ttm_bo_kmap(&bo->tbo, 0, bo->tbo.num_pages, &bo->kmap);
@@ -139,6 +141,7 @@ int qxl_bo_kmap(struct qxl_bo *bo, void **ptr)
 	bo->kptr = ttm_kmap_obj_virtual(&bo->kmap, &is_iomem);
 	if (ptr)
 		*ptr = bo->kptr;
+	bo->map_count = 1;
 	return 0;
 }
 
@@ -180,6 +183,9 @@ void qxl_bo_kunmap(struct qxl_bo *bo)
 {
 	if (bo->kptr == NULL)
 		return;
+	bo->map_count--;
+	if (bo->map_count > 0)
+		return;
 	bo->kptr = NULL;
 	ttm_bo_kunmap(&bo->kmap);
 }
diff --git a/drivers/gpu/drm/qxl/qxl_prime.c b/drivers/gpu/drm/qxl/qxl_prime.c
index a55dece118..708378844c 100644
--- a/drivers/gpu/drm/qxl/qxl_prime.c
+++ b/drivers/gpu/drm/qxl/qxl_prime.c
@@ -22,7 +22,7 @@
  * Authors: Andreas Pokorny
  */
 
-#include "qxl_drv.h"
+#include "qxl_object.h"
 
 /* Empty Implementations as there should not be any other driver for a virtual
  * device that might share buffers with qxl */
@@ -54,13 +54,22 @@ struct drm_gem_object *qxl_gem_prime_import_sg_table(
 
 void *qxl_gem_prime_vmap(struct drm_gem_object *obj)
 {
-	WARN_ONCE(1, "not implemented");
-	return ERR_PTR(-ENOSYS);
+	struct qxl_bo *bo = gem_to_qxl_bo(obj);
+	void *ptr;
+	int ret;
+
+	ret = qxl_bo_kmap(bo, &ptr);
+	if (ret < 0)
+		return ERR_PTR(ret);
+
+	return ptr;
 }
 
 void qxl_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
 {
-	WARN_ONCE(1, "not implemented");
+	struct qxl_bo *bo = gem_to_qxl_bo(obj);
+
+	qxl_bo_kunmap(bo);
 }
 
 int qxl_gem_prime_mmap(struct drm_gem_object *obj,
-- 
2.9.3


  parent reply	other threads:[~2018-12-12 13:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20181212132109.8126-1-kraxel@redhat.com>
2018-12-12 13:20 ` [PATCH v2 01/18] drm/qxl: drop ttm_mem_reg arg from qxl_hw_surface_alloc() Gerd Hoffmann
2018-12-12 13:20 ` [PATCH v2 02/18] drm/qxl: drop unused qxl_fb_virtual_address Gerd Hoffmann
2018-12-12 13:20 ` [PATCH v2 03/18] drm/qxl: simplify slot management Gerd Hoffmann
2018-12-12 13:20 ` [PATCH v2 04/18] drm/qxl: change the way slot is detected Gerd Hoffmann
2018-12-12 13:20 ` [PATCH v2 05/18] drm/qxl: drop unused fields from struct qxl_device Gerd Hoffmann
2018-12-12 13:20 ` [PATCH v2 06/18] drm/qxl: use separate offset spaces for the two slots / ttm memory types Gerd Hoffmann
2018-12-12 13:20 ` [PATCH v2 07/18] drm/qxl: allow both PRIV and VRAM placement for QXL_GEM_DOMAIN_SURFACE Gerd Hoffmann
2018-12-12 13:20 ` [PATCH v2 08/18] drm/qxl: use QXL_GEM_DOMAIN_SURFACE for shadow bo Gerd Hoffmann
2018-12-12 13:21 ` [PATCH v2 09/18] drm/qxl: use QXL_GEM_DOMAIN_SURFACE for dumb gem objects Gerd Hoffmann
2018-12-12 13:21 ` [PATCH v2 10/18] drm/qxl: move qxl_primary_apply_cursor to correct place Gerd Hoffmann
2018-12-12 13:21 ` [PATCH v2 11/18] drm/qxl: drop unused offset parameter from qxl_io_create_primary() Gerd Hoffmann
2018-12-12 13:21 ` [PATCH v2 12/18] drm/qxl: track primary bo Gerd Hoffmann
2018-12-12 13:21 ` [PATCH v2 13/18] drm/qxl: use shadow bo directly Gerd Hoffmann
2018-12-12 13:21 ` [PATCH v2 14/18] drm/qxl: cover all crtcs in shadow bo Gerd Hoffmann
2018-12-12 13:21 ` [PATCH v2 15/18] drm/qxl: use qxl_num_crtc directly Gerd Hoffmann
2018-12-12 13:21 ` Gerd Hoffmann [this message]
2018-12-12 13:21 ` [PATCH v2 17/18] drm/qxl: use generic fbdev emulation Gerd Hoffmann
2018-12-12 13:21 ` [PATCH v2 18/18] drm/qxl: remove dead qxl fbdev emulation code Gerd Hoffmann

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=20181212132109.8126-17-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=airlied@linux.ie \
    --cc=airlied@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=spice-devel@lists.freedesktop.org \
    --cc=spice-devel@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).