All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Noralf Trønnes" <noralf@tronnes.org>
To: dri-devel@lists.freedesktop.org
Cc: david@lechnology.com, daniel.vetter@ffwll.ch,
	intel-gfx@lists.freedesktop.org,
	Greg KH <gregkh@linuxfoundation.org>,
	sam@ravnborg.org
Subject: [PATCH v3 2/7] drm: Add devm_drm_dev_init()
Date: Mon, 25 Feb 2019 15:42:27 +0100	[thread overview]
Message-ID: <20190225144232.20761-3-noralf@tronnes.org> (raw)
In-Reply-To: <20190225144232.20761-1-noralf@tronnes.org>

This adds a resource managed (devres) version of drm_dev_init().

v2: Remove devm_drm_dev_register() since we can't touch hw in devm
    release functions and drivers want to disable hw on driver module
    unload (Daniel Vetter, Greg KH)

Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Greg KH <gregkh@linuxfoundation.org>
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---
 Documentation/driver-model/devres.txt |  3 +++
 drivers/gpu/drm/drm_drv.c             | 39 +++++++++++++++++++++++++++
 include/drm/drm_drv.h                 |  3 +++
 3 files changed, 45 insertions(+)

diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index b277cafce71e..351b7ac65a1e 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -254,6 +254,9 @@ DMA
   dmam_pool_create()
   dmam_pool_destroy()
 
+DRM
+  devm_drm_dev_init()
+
 GPIO
   devm_gpiod_get()
   devm_gpiod_get_index()
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index ce65f12db0fe..934780a4c033 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -601,6 +601,45 @@ int drm_dev_init(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drm_dev_init);
 
+static void devm_drm_dev_init_release(void *data)
+{
+	drm_dev_put(data);
+}
+
+/**
+ * devm_drm_dev_init - Resource managed drm_dev_init()
+ * @parent: Parent device object
+ * @dev: DRM device
+ * @driver: DRM driver
+ *
+ * Managed drm_dev_init(). The DRM device initialized with this function is
+ * automatically put on driver detach using drm_dev_put(). You must supply a
+ * &drm_driver.release callback to control the finalization explicitly.
+ *
+ * RETURNS:
+ * 0 on success, or error code on failure.
+ */
+int devm_drm_dev_init(struct device *parent,
+		      struct drm_device *dev,
+		      struct drm_driver *driver)
+{
+	int ret;
+
+	if (WARN_ON(!parent || !driver->release))
+		return -EINVAL;
+
+	ret = drm_dev_init(dev, driver, parent);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action(parent, devm_drm_dev_init_release, dev);
+	if (ret)
+		devm_drm_dev_init_release(dev);
+
+	return ret;
+}
+EXPORT_SYMBOL(devm_drm_dev_init);
+
 /**
  * drm_dev_fini - Finalize a dead DRM device
  * @dev: DRM device
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index ca46a45a9cce..e81bce2698e3 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -718,6 +718,9 @@ extern unsigned int drm_debug;
 int drm_dev_init(struct drm_device *dev,
 		 struct drm_driver *driver,
 		 struct device *parent);
+int devm_drm_dev_init(struct device *parent,
+		      struct drm_device *dev,
+		      struct drm_driver *driver);
 void drm_dev_fini(struct drm_device *dev);
 
 struct drm_device *drm_dev_alloc(struct drm_driver *driver,
-- 
2.20.1

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

  parent reply	other threads:[~2019-02-25 14:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-25 14:42 [PATCH v3 0/7] drm/tinydrm: Remove tinydrm_device Noralf Trønnes
2019-02-25 14:42 ` [PATCH v3 1/7] drm/drv: Hold ref on parent device during drm_device lifetime Noralf Trønnes
2019-02-27 14:13   ` Gerd Hoffmann
2019-02-25 14:42 ` Noralf Trønnes [this message]
2019-02-27 14:15   ` [PATCH v3 2/7] drm: Add devm_drm_dev_init() Gerd Hoffmann
2019-02-25 14:42 ` [PATCH v3 3/7] drm/drv: DOC: Add driver example code Noralf Trønnes
2019-02-27 14:19   ` Gerd Hoffmann
2019-02-25 14:42 ` [PATCH v3 4/7] drm/tinydrm/repaper: Drop using tinydrm_device Noralf Trønnes
2019-02-25 14:42 ` [PATCH v3 5/7] drm/tinydrm: " Noralf Trønnes
2019-02-27 14:27   ` Gerd Hoffmann
2019-02-27 17:03     ` Noralf Trønnes
2019-02-25 14:42 ` [PATCH v3 6/7] drm/tinydrm: Remove tinydrm_device Noralf Trønnes
2019-02-25 14:42 ` [PATCH v3 7/7] drm/tinydrm: Use drm_dev_enter/exit() Noralf Trønnes
2019-02-27 14:30   ` Gerd Hoffmann
2019-02-25 15:05 ` ✗ Fi.CI.CHECKPATCH: warning for drm/tinydrm: Remove tinydrm_device Patchwork
2019-02-25 15:25 ` ✓ Fi.CI.BAT: success " Patchwork
2019-02-25 21:03 ` ✓ Fi.CI.IGT: " Patchwork
2019-03-04 14:40 ` [PATCH v3 0/7] " Noralf Trønnes

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=20190225144232.20761-3-noralf@tronnes.org \
    --to=noralf@tronnes.org \
    --cc=daniel.vetter@ffwll.ch \
    --cc=david@lechnology.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=sam@ravnborg.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 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.