dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: daniel@ffwll.ch, airlied@linux.ie, kraxel@redhat.com,
	christian.koenig@amd.com, ray.huang@amd.com, Jerry.Zhang@amd.com,
	hdegoede@redhat.com, z.liuxinliang@hisilicon.com,
	zourongrong@gmail.com, kong.kongxinwei@hisilicon.com,
	puck.chen@hisilicon.com
Cc: Thomas Zimmermann <tzimmermann@suse.de>,
	dri-devel@lists.freedesktop.org,
	virtualization@lists.linux-foundation.org
Subject: [PATCH 04/15] drm: Add drm_gem_ttm_fill_create_dumb() to create dumb buffers
Date: Mon,  8 Apr 2019 11:21:33 +0200	[thread overview]
Message-ID: <20190408092144.4548-5-tzimmermann@suse.de> (raw)
In-Reply-To: <20190408092144.4548-1-tzimmermann@suse.de>

The helper function drm_gem_ttm_fill_create_dumb() implements most of
struct drm_driver.dumb_create() for GEM TTM buffer objects. It's not a
full implemenation of the callback, as several driver-specific parameters
are still required.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_gem_ttm_helper.c | 62 ++++++++++++++++++++++++++++
 include/drm/drm_gem_ttm_helper.h     |  8 ++++
 2 files changed, 70 insertions(+)

diff --git a/drivers/gpu/drm/drm_gem_ttm_helper.c b/drivers/gpu/drm/drm_gem_ttm_helper.c
index d4950517e357..a2306e27db13 100644
--- a/drivers/gpu/drm/drm_gem_ttm_helper.c
+++ b/drivers/gpu/drm/drm_gem_ttm_helper.c
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 
 #include <drm/drm_gem_ttm_helper.h>
+#include <drm/drm_mode.h>
 #include <drm/ttm/ttm_page_alloc.h>
 
 /**
@@ -366,6 +367,67 @@ bool drm_is_gem_ttm(struct ttm_buffer_object *bo)
 }
 EXPORT_SYMBOL(drm_is_gem_ttm);
 
+/**
+ * drm_gem_ttm_fill_create_dumb() - \
+	Helper for implementing struct drm_driver.dumb_create
+ * @file:		the DRM file
+ * @dev:		the DRM device
+ * @bdev:		the TTM BO device managing the buffer object
+ * @pg_align:		the buffer's alignment in multiples of the page size
+ * @interruptible:	sleep interruptible if waiting for memory
+ * @args:		the arguments as provided to \
+				struct drm_driver.dumb_create
+ *
+ * This helper function fills struct drm_mode_create_dumb, which is used
+ * by struct drm_driver.dumb_create. Implementations of this interface
+ * should forwards their arguments to this helper; plus the driver-specific
+ * parameters.
+ *
+ * Returns:
+ * 0 on success, or
+ * a negative error code otherwise.
+ */
+int drm_gem_ttm_fill_create_dumb(struct drm_file *file,
+				 struct drm_device *dev,
+				 struct ttm_bo_device *bdev,
+				 uint32_t pg_align,
+				 bool interruptible,
+				 struct drm_mode_create_dumb *args)
+{
+	size_t pitch, size;
+	struct drm_gem_ttm_object *gbo;
+	int ret;
+	u32 handle;
+
+	pitch = args->width * ((args->bpp + 7) / 8);
+	size = pitch * args->height;
+
+	size = roundup(size, PAGE_SIZE);
+	if (!size)
+		return -EINVAL;
+
+	gbo = drm_gem_ttm_create(dev, bdev, size, pg_align, interruptible);
+	if (IS_ERR(gbo))
+		return PTR_ERR(gbo);
+
+	ret = drm_gem_handle_create(file, &gbo->gem, &handle);
+	if (ret)
+		goto err_drm_gem_object_put_unlocked;
+
+	drm_gem_object_put_unlocked(&gbo->gem);
+
+	args->pitch = pitch;
+	args->size = size;
+	args->handle = handle;
+
+	return 0;
+
+err_drm_gem_object_put_unlocked:
+	drm_gem_object_put_unlocked(&gbo->gem);
+	return ret;
+}
+EXPORT_SYMBOL(drm_gem_ttm_fill_create_dumb);
+
 /*
  * Helpers for struct ttm_bo_driver
  */
diff --git a/include/drm/drm_gem_ttm_helper.h b/include/drm/drm_gem_ttm_helper.h
index edc2093588ff..3918dfca1d58 100644
--- a/include/drm/drm_gem_ttm_helper.h
+++ b/include/drm/drm_gem_ttm_helper.h
@@ -8,6 +8,7 @@
 #include <drm/ttm/ttm_placement.h>
 #include <linux/kernel.h> /* for container_of() */
 
+struct drm_mode_create_dumb;
 struct filp;
 
 /*
@@ -88,6 +89,13 @@ void drm_gem_ttm_kunmap(struct drm_gem_ttm_object *gbo);
 
 bool drm_is_gem_ttm(struct ttm_buffer_object *bo);
 
+int drm_gem_ttm_fill_create_dumb(struct drm_file *file,
+				 struct drm_device *dev,
+				 struct ttm_bo_device *bdev,
+				 uint32_t pg_align,
+				 bool interruptible,
+				 struct drm_mode_create_dumb *args);
+
 /*
  * Helpers for struct ttm_bo_driver
  */
-- 
2.21.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2019-04-08  9:21 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-08  9:21 [PATCH 00/15] Share TTM code among framebuffer drivers Thomas Zimmermann
2019-04-08  9:21 ` [PATCH 01/15] drm: Add |struct drm_gem_ttm_object| and helpers Thomas Zimmermann
2019-04-08  9:21 ` [PATCH 02/15] drm: Add |struct drm_gem_ttm_object| callbacks for |struct ttm_bo_driver| Thomas Zimmermann
2019-04-08  9:21 ` [PATCH 03/15] drm: Add |struct drm_gem_ttm_object| callbacks for |struct drm_driver| Thomas Zimmermann
2019-04-08  9:21 ` Thomas Zimmermann [this message]
2019-04-08  9:21 ` [PATCH 05/15] drm: Add Simple TTM, a memory manager for dedicated VRAM Thomas Zimmermann
2019-04-08  9:21 ` [PATCH 06/15] drm/ast: Convert AST driver to |struct drm_gem_ttm_object| Thomas Zimmermann
2019-04-08  9:21 ` [PATCH 07/15] drm/ast: Convert AST driver to Simple TTM Thomas Zimmermann
2019-04-08  9:21 ` [PATCH 08/15] drm/bochs: Convert Bochs driver to |struct drm_gem_ttm_object| Thomas Zimmermann
2019-04-08  9:21 ` [PATCH 09/15] drm/bochs: Convert Bochs driver to Simple TTM Thomas Zimmermann
2019-04-08  9:21 ` [PATCH 10/15] drm/mgag200: Convert mgag200 driver to |struct drm_gem_ttm_object| Thomas Zimmermann
2019-04-08  9:21 ` [PATCH 11/15] drm/mgag200: Convert mgag200 driver to Simple TTM Thomas Zimmermann
2019-04-08  9:21 ` [PATCH 12/15] drm/vboxvideo: Convert vboxvideo driver to |struct drm_gem_ttm_object| Thomas Zimmermann
2019-04-09  7:09   ` Hans de Goede
2019-04-08  9:21 ` [PATCH 13/15] drm/vboxvideo: Convert vboxvideo driver to Simple TTM Thomas Zimmermann
2019-04-09  7:09   ` Hans de Goede
2019-04-09  7:37     ` Thomas Zimmermann
2019-04-08  9:21 ` [PATCH 14/15] drm/hisilicon: Convert hibmc-drm driver to |struct drm_gem_ttm_object| Thomas Zimmermann
2019-04-08  9:21 ` [PATCH 15/15] drm/hisilicon: Convert hibmc-drm driver to Simple TTM Thomas Zimmermann
2019-04-08 11:10 ` [PATCH 00/15] Share TTM code among framebuffer drivers Koenig, Christian
2019-04-08 11:59   ` Thomas Zimmermann
2019-04-09  7:12     ` kraxel
2019-04-09  7:42       ` Dave Airlie
2019-04-09  8:29         ` kraxel
2019-04-09 11:55           ` Christian König
2019-04-09  7:50       ` Thomas Zimmermann
2019-04-15 15:54         ` Daniel Vetter
2019-04-15 15:57           ` Daniel Vetter
2019-04-15 16:21           ` Thomas Zimmermann
2019-04-15 19:17             ` Daniel Vetter
2019-04-16 10:05               ` Koenig, Christian
2019-04-16 11:03                 ` Daniel Vetter
2019-04-16 11:10                   ` Koenig, Christian
2019-04-09 13:39     ` Koenig, Christian

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=20190408092144.4548-5-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=Jerry.Zhang@amd.com \
    --cc=airlied@linux.ie \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hdegoede@redhat.com \
    --cc=kong.kongxinwei@hisilicon.com \
    --cc=kraxel@redhat.com \
    --cc=puck.chen@hisilicon.com \
    --cc=ray.huang@amd.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=z.liuxinliang@hisilicon.com \
    --cc=zourongrong@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox