All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime@cerno.tech>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Maxime Ripard <maxime@cerno.tech>,
	Daniel Vetter <daniel.vetter@intel.com>,
	David Airlie <airlied@linux.ie>
Cc: dri-devel@lists.freedesktop.org
Subject: [PATCH v3 03/71] drm/encoder: Introduce drmm_encoder_init
Date: Wed, 29 Jun 2022 14:34:02 +0200	[thread overview]
Message-ID: <20220629123510.1915022-4-maxime@cerno.tech> (raw)
In-Reply-To: <20220629123510.1915022-1-maxime@cerno.tech>

The DRM-managed function to register an encoder is
drmm_encoder_alloc() and its variants, which will allocate the underlying
structure and initialisation the encoder.

However, we might want to separate the structure creation and the encoder
initialisation, for example if the structure is shared across multiple DRM
entities, for example an encoder and a connector.

Let's create an helper to only initialise an encoder that would be passed
as an argument.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
 drivers/gpu/drm/drm_encoder.c | 76 ++++++++++++++++++++++++++++++-----
 include/drm/drm_encoder.h     |  6 +++
 2 files changed, 71 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
index a940024c8087..ae2da4be080b 100644
--- a/drivers/gpu/drm/drm_encoder.c
+++ b/drivers/gpu/drm/drm_encoder.c
@@ -148,9 +148,9 @@ static int __drm_encoder_init(struct drm_device *dev,
  * the encoder structure. The encoder structure should not be allocated with
  * devm_kzalloc().
  *
- * Note: consider using drmm_encoder_alloc() instead of drm_encoder_init() to
- * let the DRM managed resource infrastructure take care of cleanup and
- * deallocation.
+ * Note: consider using drmm_encoder_alloc() or drmm_encoder_init()
+ * instead of drm_encoder_init() to let the DRM managed resource
+ * infrastructure take care of cleanup and deallocation.
  *
  * Returns:
  * Zero on success, error code on failure.
@@ -212,6 +212,29 @@ static void drmm_encoder_alloc_release(struct drm_device *dev, void *ptr)
 	drm_encoder_cleanup(encoder);
 }
 
+static int __drmm_encoder_init(struct drm_device *dev,
+			       struct drm_encoder *encoder,
+			       const struct drm_encoder_funcs *funcs,
+			       int encoder_type,
+			       const char *name,
+			       va_list args)
+{
+	int ret;
+
+	if (WARN_ON(funcs && funcs->destroy))
+		return -EINVAL;
+
+	ret = __drm_encoder_init(dev, encoder, funcs, encoder_type, name, args);
+	if (ret)
+		return ret;
+
+	ret = drmm_add_action_or_reset(dev, drmm_encoder_alloc_release, encoder);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 void *__drmm_encoder_alloc(struct drm_device *dev, size_t size, size_t offset,
 			   const struct drm_encoder_funcs *funcs,
 			   int encoder_type, const char *name, ...)
@@ -221,9 +244,6 @@ void *__drmm_encoder_alloc(struct drm_device *dev, size_t size, size_t offset,
 	va_list ap;
 	int ret;
 
-	if (WARN_ON(funcs && funcs->destroy))
-		return ERR_PTR(-EINVAL);
-
 	container = drmm_kzalloc(dev, size, GFP_KERNEL);
 	if (!container)
 		return ERR_PTR(-ENOMEM);
@@ -231,19 +251,53 @@ void *__drmm_encoder_alloc(struct drm_device *dev, size_t size, size_t offset,
 	encoder = container + offset;
 
 	va_start(ap, name);
-	ret = __drm_encoder_init(dev, encoder, funcs, encoder_type, name, ap);
+	ret = __drmm_encoder_init(dev, encoder, funcs, encoder_type, name, ap);
 	va_end(ap);
 	if (ret)
 		return ERR_PTR(ret);
 
-	ret = drmm_add_action_or_reset(dev, drmm_encoder_alloc_release, encoder);
-	if (ret)
-		return ERR_PTR(ret);
-
 	return container;
 }
 EXPORT_SYMBOL(__drmm_encoder_alloc);
 
+/**
+ * drmm_encoder_init - Initialize a preallocated encoder
+ * @dev: drm device
+ * @encoder: the encoder to init
+ * @funcs: callbacks for this encoder (optional)
+ * @encoder_type: user visible type of the encoder
+ * @name: printf style format string for the encoder name, or NULL for default name
+ *
+ * Initializes a preallocated encoder. Encoder should be subclassed as
+ * part of driver encoder objects. Cleanup is automatically handled
+ * through registering drm_encoder_cleanup() with drmm_add_action(). The
+ * encoder structure should be allocated with drmm_kzalloc().
+ *
+ * The @drm_encoder_funcs.destroy hook must be NULL.
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ */
+int drmm_encoder_init(struct drm_device *dev, struct drm_encoder *encoder,
+		      const struct drm_encoder_funcs *funcs,
+		      int encoder_type, const char *name, ...)
+{
+	va_list ap;
+	int ret;
+
+	if (WARN_ON(funcs && funcs->destroy))
+		return -EINVAL;
+
+	va_start(ap, name);
+	ret = __drmm_encoder_init(dev, encoder, funcs, encoder_type, name, ap);
+	va_end(ap);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+EXPORT_SYMBOL(drmm_encoder_init);
+
 static struct drm_crtc *drm_encoder_get_crtc(struct drm_encoder *encoder)
 {
 	struct drm_connector *connector;
diff --git a/include/drm/drm_encoder.h b/include/drm/drm_encoder.h
index 6e91a0280f31..3a09682af685 100644
--- a/include/drm/drm_encoder.h
+++ b/include/drm/drm_encoder.h
@@ -194,6 +194,12 @@ int drm_encoder_init(struct drm_device *dev,
 		     const struct drm_encoder_funcs *funcs,
 		     int encoder_type, const char *name, ...);
 
+__printf(5, 6)
+int drmm_encoder_init(struct drm_device *dev,
+		      struct drm_encoder *encoder,
+		      const struct drm_encoder_funcs *funcs,
+		      int encoder_type, const char *name, ...);
+
 __printf(6, 7)
 void *__drmm_encoder_alloc(struct drm_device *dev,
 			   size_t size, size_t offset,
-- 
2.36.1


  parent reply	other threads:[~2022-06-29 12:35 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-29 12:33 [PATCH v3 00/71] drm/vc4: Fix hotplug for vc4 Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 01/71] drm/mipi-dsi: Detach devices when removing the host Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 02/71] drm/crtc: Introduce drmm_crtc_init_with_planes Maxime Ripard
2022-06-29 12:34 ` Maxime Ripard [this message]
2022-06-29 13:32   ` [PATCH v3 03/71] drm/encoder: Introduce drmm_encoder_init Philipp Zabel
2022-06-29 14:41     ` Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 04/71] drm/connector: Reorder headers Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 05/71] drm/connector: Mention the cleanup after drm_connector_init Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 06/71] drm/connector: Clarify when drm_connector_unregister is needed Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 07/71] drm/connector: Consolidate Connector Initialization Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 08/71] drm/connector: Check for destroy implementation Maxime Ripard
2022-06-29 13:04   ` Jani Nikula
2022-06-29 12:34 ` [PATCH v3 09/71] drm/connector: Introduce drmm_connector_init Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 10/71] drm/bridge: panel: Introduce drmm_panel_bridge_add Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 11/71] drm/bridge: panel: Introduce drmm_of_get_bridge Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 12/71] drm/vc4: drv: Call component_unbind_all() Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 13/71] drm/vc4: drv: Use drm_dev_unplug Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 14/71] drm/vc4: crtc: Create vblank reporting function Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 15/71] drm/vc4: hvs: Protect device resources after removal Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 16/71] drm/vc4: hvs: Remove planes currently allocated before taking down Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 17/71] drm/vc4: plane: Take possible_crtcs as an argument Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 18/71] drm/vc4: crtc: Remove manual plane removal on error Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 19/71] drm/vc4: plane: Switch to drmm_universal_plane_alloc() Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 20/71] drm/vc4: crtc: Move debugfs_name to crtc_data Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 21/71] drm/vc4: crtc: Switch to drmm_kzalloc Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 22/71] drm/vc4: crtc: Switch to DRM-managed CRTC initialization Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 23/71] drm/vc4: dpi: Remove vc4_dev dpi pointer Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 24/71] drm/vc4: dpi: Embed DRM structures into the private structure Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 25/71] drm/vc4: dpi: Switch to drmm_kzalloc Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 26/71] drm/vc4: dpi: Return an error if we can't enable our clock Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 27/71] drm/vc4: dpi: Remove unnecessary drm_of_panel_bridge_remove call Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 28/71] drm/vc4: dpi: Add action to disable the clock Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 29/71] drm/vc4: dpi: Switch to DRM-managed encoder initialization Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 30/71] drm/vc4: dpi: Switch to drmm_of_get_bridge Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 31/71] drm/vc4: dpi: Protect device resources Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 32/71] drm/vc4: dsi: Embed DRM structures into the private structure Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 33/71] drm/vc4: dsi: Switch to DRM-managed encoder initialization Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 34/71] drm/vc4: dsi: Switch to drmm_of_get_bridge Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 35/71] drm/vc4: dsi: Fix the driver structure lifetime Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 36/71] drm/vc4: dsi: Switch to devm_pm_runtime_enable Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 37/71] drm/vc4: hdmi: Depends on CONFIG_PM Maxime Ripard
2022-07-08  9:42   ` (subset) " Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 38/71] drm/vc4: hdmi: Rework power up Maxime Ripard
2022-07-08  9:42   ` (subset) " Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 39/71] drm/vc4: hdmi: Switch to drmm_kzalloc Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 40/71] drm/vc4: hdmi: Remove call to drm_connector_unregister() Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 41/71] drm/vc4: hdmi: Switch to DRM-managed encoder initialization Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 42/71] drm/vc4: hdmi: Switch to DRM-managed connector initialization Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 43/71] drm/vc4: hdmi: Switch to device-managed ALSA initialization Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 44/71] drm/vc4: hdmi: Switch to device-managed CEC initialization Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 45/71] drm/vc4: hdmi: Use a device-managed action for DDC Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 46/71] drm/vc4: hdmi: Switch to DRM-managed kfree to build regsets Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 47/71] drm/vc4: hdmi: Use devm to register hotplug interrupts Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 48/71] drm/vc4: hdmi: Move audio structure offset checks Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 49/71] drm/vc4: hdmi: Protect device resources after removal Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 50/71] drm/vc4: hdmi: Switch to devm_pm_runtime_enable Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 51/71] drm/vc4: txp: Remove vc4_dev txp pointer Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 52/71] drm/vc4: txp: Remove duplicate regset Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 53/71] drm/vc4: txp: Switch to drmm_kzalloc Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 54/71] drm/vc4: txp: Remove call to drm_connector_unregister() Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 55/71] drm/vc4: txp: Protect device resources Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 56/71] drm/vc4: vec: Remove vc4_dev vec pointer Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 57/71] drm/vc4: vec: Embed DRM structures into the private structure Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 58/71] drm/vc4: vec: Switch to drmm_kzalloc Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 59/71] drm/vc4: vec: Remove call to drm_connector_unregister() Maxime Ripard
2022-06-29 12:34 ` [PATCH v3 60/71] drm/vc4: vec: Switch to DRM-managed encoder initialization Maxime Ripard
2022-06-29 12:35 ` [PATCH v3 61/71] drm/vc4: vec: Switch to DRM-managed connector initialization Maxime Ripard
2022-06-29 12:35 ` [PATCH v3 62/71] drm/vc4: vec: Protect device resources after removal Maxime Ripard
2022-06-29 12:35 ` [PATCH v3 63/71] drm/vc4: vec: Switch to devm_pm_runtime_enable Maxime Ripard
2022-06-29 12:35 ` [PATCH v3 64/71] drm/vc4: debugfs: Protect device resources Maxime Ripard
2022-06-29 12:35 ` [PATCH v3 65/71] drm/vc4: debugfs: Return an error on failure Maxime Ripard
2022-06-29 12:35 ` [PATCH v3 66/71] drm/vc4: debugfs: Simplify debugfs registration Maxime Ripard
2022-06-29 12:35 ` [PATCH v3 67/71] drm/vc4: Switch to drmm_mutex_init Maxime Ripard
2022-06-29 12:35 ` [PATCH v3 68/71] drm/vc4: perfmon: Add missing mutex_destroy Maxime Ripard
2022-06-29 12:35 ` [PATCH v3 69/71] drm/vc4: v3d: Stop disabling interrupts Maxime Ripard
2022-06-29 12:35 ` [PATCH v3 70/71] drm/vc4: v3d: Rework the runtime_pm setup Maxime Ripard
2022-06-29 12:35 ` [PATCH v3 71/71] drm/vc4: v3d: Switch to devm_pm_runtime_enable Maxime Ripard
2022-07-07  6:48 ` [PATCH v3 00/71] drm/vc4: Fix hotplug for vc4 Thomas Zimmermann

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=20220629123510.1915022-4-maxime@cerno.tech \
    --to=maxime@cerno.tech \
    --cc=airlied@linux.ie \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=tzimmermann@suse.de \
    /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.