mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: dri-devel@lists.freedesktop.org
Cc: Gerd Hoffmann <kraxel@redhat.com>,
	David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
	virtualization@lists.linux-foundation.org (open list:VIRTIO GPU
	DRIVER), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v4 07/12] drm/virtio: add virtio_gpu_object_array & helpers
Date: Thu, 20 Jun 2019 08:07:21 +0200	[thread overview]
Message-ID: <20190620060726.926-8-kraxel@redhat.com> (raw)
In-Reply-To: <20190620060726.926-1-kraxel@redhat.com>

Some helper functions to manage an array of gem objects.

v4: make them virtio-private instead of generic helpers.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 drivers/gpu/drm/virtio/virtgpu_drv.h | 10 ++++++
 drivers/gpu/drm/virtio/virtgpu_gem.c | 50 ++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h
index 07f6001ea91e..98d646789d23 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.h
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.h
@@ -84,6 +84,11 @@ struct virtio_gpu_object {
 #define gem_to_virtio_gpu_obj(gobj) \
 	container_of((gobj), struct virtio_gpu_object, gem_base)
 
+struct virtio_gpu_object_array {
+	u32 nents;
+	struct drm_gem_object *objs[];
+};
+
 struct virtio_gpu_vbuffer;
 struct virtio_gpu_device;
 
@@ -251,6 +256,11 @@ int virtio_gpu_mode_dumb_mmap(struct drm_file *file_priv,
 			      struct drm_device *dev,
 			      uint32_t handle, uint64_t *offset_p);
 
+struct virtio_gpu_object_array *virtio_gpu_array_alloc(u32 nents);
+struct virtio_gpu_object_array*
+virtio_gpu_array_from_handles(struct drm_file *drm_file, u32 *handles, u32 nents);
+void virtio_gpu_array_put_free(struct virtio_gpu_object_array *objs);
+
 /* virtio vg */
 int virtio_gpu_alloc_vbufs(struct virtio_gpu_device *vgdev);
 void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev);
diff --git a/drivers/gpu/drm/virtio/virtgpu_gem.c b/drivers/gpu/drm/virtio/virtgpu_gem.c
index 9c9ad3b14080..456cc382ce68 100644
--- a/drivers/gpu/drm/virtio/virtgpu_gem.c
+++ b/drivers/gpu/drm/virtio/virtgpu_gem.c
@@ -169,3 +169,53 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj,
 						qobj->hw_res_handle);
 	virtio_gpu_object_unreserve(qobj);
 }
+
+struct virtio_gpu_object_array *virtio_gpu_array_alloc(u32 nents)
+{
+	struct virtio_gpu_object_array *objs;
+	size_t size = sizeof(*objs) + sizeof(objs->objs[0]) * nents;
+
+	objs = kzalloc(size, GFP_KERNEL);
+	if (!objs)
+		return NULL;
+
+	objs->nents = nents;
+	return objs;
+}
+
+static void virtio_gpu_array_free(struct virtio_gpu_object_array *objs)
+{
+	kfree(objs);
+}
+
+struct virtio_gpu_object_array*
+virtio_gpu_array_from_handles(struct drm_file *drm_file, u32 *handles, u32 nents)
+{
+	struct virtio_gpu_object_array *objs;
+	u32 i;
+
+	objs = virtio_gpu_array_alloc(nents);
+	if (!objs)
+		return NULL;
+
+	for (i = 0; i < nents; i++) {
+		objs->objs[i] = drm_gem_object_lookup(drm_file, handles[i]);
+		if (!objs->objs[i]) {
+			virtio_gpu_array_put_free(objs);
+			return NULL;
+		}
+	}
+	return objs;
+}
+
+void virtio_gpu_array_put_free(struct virtio_gpu_object_array *objs)
+{
+	u32 i;
+
+	for (i = 0; i < objs->nents; i++) {
+		if (!objs->objs[i])
+			continue;
+		drm_gem_object_put_unlocked(objs->objs[i]);
+	}
+	virtio_gpu_array_free(objs);
+}
-- 
2.18.1


  parent reply	other threads:[~2019-06-20  6:07 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20190620060726.926-1-kraxel@redhat.com>
2019-06-20  6:07 ` [PATCH v4 01/12] drm/virtio: pass gem reservation object to ttm init Gerd Hoffmann
2019-06-20  6:07 ` [PATCH v4 02/12] drm/virtio: switch virtio_gpu_wait_ioctl() to gem helper Gerd Hoffmann
2019-06-26 23:55   ` Chia-I Wu
2019-06-28 10:05     ` Gerd Hoffmann
2019-06-30 18:56       ` Chia-I Wu
2019-06-20  6:07 ` [PATCH v4 03/12] drm/virtio: simplify cursor updates Gerd Hoffmann
2019-06-20  6:07 ` [PATCH v4 04/12] drm/virtio: remove virtio_gpu_object_wait Gerd Hoffmann
2019-06-20  6:07 ` [PATCH v4 05/12] drm/virtio: drop no_wait argument from virtio_gpu_object_reserve Gerd Hoffmann
2019-06-20  6:07 ` [PATCH v4 06/12] drm/virtio: remove ttm calls from in virtio_gpu_object_{reserve,unreserve} Gerd Hoffmann
2019-06-20  6:07 ` Gerd Hoffmann [this message]
2019-06-27  0:49   ` [PATCH v4 07/12] drm/virtio: add virtio_gpu_object_array & helpers Chia-I Wu
2019-06-20  6:07 ` [PATCH v4 08/12] drm/virtio: rework virtio_gpu_execbuffer_ioctl fencing Gerd Hoffmann
2019-06-27  1:32   ` Chia-I Wu
2019-06-28 10:34     ` Gerd Hoffmann
2019-06-30 18:47       ` Chia-I Wu
2019-06-20  6:07 ` [PATCH v4 09/12] drm/virtio: rework virtio_gpu_object_create fencing Gerd Hoffmann
2019-06-27  1:44   ` Chia-I Wu
2019-06-20  6:07 ` [PATCH v4 10/12] drm/virtio: drop virtio_gpu_object_list_validate/virtio_gpu_unref_list Gerd Hoffmann
2019-06-20  6:07 ` [PATCH v4 11/12] drm/virtio: switch from ttm to gem shmem helpers Gerd Hoffmann
2019-06-27  4:47   ` Chia-I Wu
2019-06-28 10:49     ` Gerd Hoffmann
2019-06-30 18:42       ` Chia-I Wu
2019-06-20  6:07 ` [PATCH v4 12/12] drm/virtio: remove virtio_gpu_alloc_object 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=20190620060726.926-8-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®